package com.zl.csMall.mine.favorites.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zl.csMall.mine.favorites.mapper.FavoritesMapper;
import com.zl.csMall.mine.favorites.po.Favorites;
import com.zl.csMall.mine.favorites.service.FavoritesService;
import org.springframework.stereotype.Service;

/**
 * @description: FavoritesServiceImpl
 * @author: ChenNing
 * @date 2025-10-21 14:18
 */
@Service
public class FavoritesServiceImpl extends ServiceImpl<FavoritesMapper, Favorites> implements FavoritesService {


    @Override
    public boolean isExistence(long userId, long commodityId, boolean isDelete) {
        LambdaQueryWrapper<Favorites> favoritesQuery = new LambdaQueryWrapper<>();
        favoritesQuery.select(Favorites::getId)
                .eq(Favorites::getUserId, userId)
                .eq(Favorites::getCommodityId, commodityId);
        boolean existence = this.getBaseMapper().selectCount(favoritesQuery) > 0;
        if (isDelete && existence){
            return this.remove(favoritesQuery);
        }
        return existence;
    }

}
